package cn.edu.hunau.java.week03.day04;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class FileTest {

    @Test
    public void testFile01(){
        File f1=new File(".");
        System.out.println("绝对路径:"+f1.getAbsolutePath());
        System.out.println("名称:"+f1.getName());
        System.out.println("是否为目录:"+f1.isDirectory());
        System.out.println("是否在磁盘中存在:"+f1.exists());
    }

    @Test
    public void testFileCreat() throws IOException {
        File f1=new File("dir");
        if(!f1.exists()){
            f1.mkdir();
        }
        File f2=new File("dir/zmz.text");
        if(!f2.exists()){
            f2.createNewFile();
        }
        System.out.println("是否为文件:"+f2.isFile());
        System.out.println("是否可操作:"+f2.canExecute());
        f2.renameTo(new File("dir/hsl.text"));
    }

    @Test
    public void testFile02() throws IOException {
        Path temp=Path.of("temp");
        if(!Files.exists(temp)){
            Path tempDir=Files.createDirectories(Path.of("temp"));
        }
        Files.createDirectories(Path.of("temp"));
    }

    @Test
    public void testDelete() throws IOException {
        Files.deleteIfExists(Path.of("dir/hsl.text"));
        boolean isDelete=Files.notExists(Path.of("dir/hsl.text"));
        System.out.println(isDelete);
    }
}
